/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package learn;

import dataset.GMBReader;
import java.util.List;
import parse.CCGDerivation;
import parse.CCGLexNode;

/**
 *
 * @author phong
 */
public class Learner {
    
    Lexicon lexicon;
    String gmbPath = "../gmb-1.0.0";
//    String gmbPath = "../gmb-small";
    
    public Learner() {
        lexicon = null;
    }
    
    public String getTokens(List<CCGLexNode> lexNodes) {
        StringBuffer buff = new StringBuffer();
        for (CCGLexNode lnode : lexNodes) {
            buff.append(lnode.getLexSurface().getToken()).append(" ");
        }
        return buff.toString();
    }
    
    public void learn() {
        
        // learn lexicon
        lexicon = new Lexicon();
        
        GMBReader gmbReader = new GMBReader();
        gmbReader.open(gmbPath);
        
        while (gmbReader.hasNext()) {
            List<CCGDerivation> ders = gmbReader.next();
            for (CCGDerivation der : ders) {
                List<CCGLexNode> lexNodes = der.getLexNodes();
                System.out.println(getTokens(lexNodes));
                
                for (CCGLexNode lnode : lexNodes) {
                    LexicalEntry le = lnode.getLexEntry();
                    lexicon.add(le);
                }
            }
        }
    }
    
    public static void main(String[] args) {
        Learner learner = new Learner();
        learner.learn();
    }
    
}
